<?php
/**
 * Green Calc
 * Calc template for main view
 * 2009-2014 All rights reserved
 * @link http://www.greenkey.ru
 * @license GNU/GPL v3
 */
// No direct access
defined('_JEXEC') or die;
?>

<?php if ($this->item->params->get('show_page_heading')) : ?>
    <h1>
        <?php echo $this->escape($this->item->params->get('page_heading')); ?>
    </h1>
<?php endif; ?>

<h2>
<?php echo $this->item->caption; ?>
</h2>
<p>
    <?php echo JText::_($this->item->description); ?>
</p>

<script> 
    function calc_me() {
        <?php
        foreach ($this->inputs as $key => $value) echo "var " . $key . " = parseFloat(jQuery('#calc_" . $key . "').val());\n";
        ?>
        var value = ' ';
        <?php echo $this->item->formula . "\n"; ?>
        jQuery('#calc_result').html(value);
    }
</script>

<fieldset>
    <legend><?php echo JText::_('COM_CALC_INPUTS'); ?></legend>
    <table>
        <?php foreach ($this->inputs as $key => $value) { ?>
            <tr>
                <td align="right">
                    <label for="calc_<?php echo $key; ?>"><?php echo JText::_($value->desc); ?></label>
                </td>
                <td>
                    <?php if ($value->options) : ?>
                        <select name="calc_<?php echo $key; ?>" id="calc_<?php echo $key; ?>">;
                            <?php foreach ($value->options as $k => $v)
                                echo '<option value="' . $k . '">' . JText::_($v) . "</option>\n"; ?>
                        </select>
                    <?php else : ?>
                        <input type="text" name="calc_<?php echo $key; ?>" id="calc_<?php echo $key; ?>" size="20" class="inputbox" />
                    <?php endif; ?>
            </td>
        </tr>
        <?php } ?>
    </table>
</fieldset>
<p>
    <button id="start" class="btn btn-primary" onclick="calc_me()"><?php echo JText::_('COM_CALC_CALCUTATE'); ?></button>
</p>    
<fieldset>
    <legend><?php echo JText::_('COM_CALC_RESULT').":"; ?></legend>
    <div id="calc_result">&nbsp;</div>
</fieldset>

